﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JNCY.Win
{
    public partial class Form1 : UIForm
    {
        CHCNetHelper ch = new CHCNetHelper();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
            ch.Inits();

            ch.UserLogin();

            ch.SetInfo();

            ch.DataCallBack = (i) => {
                this.Invoke(new EventHandler(delegate {
                    lblName.Text = i.Name;
                    lblSex.Text = i.Sex;
                    lblNation.Text = i.Nation;
                    lblAddress.Text = i.Address;
                    lblCardNo.Text = i.CardNo;
                    lblBrith.Text = i.BirthDay;

                    try
                    {
                        using(System.IO.MemoryStream ms=new System.IO.MemoryStream(i.CardImgByte))
                        {
                            pictureBox1.Image = Image.FromStream(ms);
                        }
                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream(i.FaceImgByte))
                        {
                            pictureBox2.Image = Image.FromStream(ms);
                        }
                    }
                    catch(Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                    }

                   lblTime.Text = DateTime.Now.ToString();

                    
                   lblResult.Text = "认证成功";
                   lblResult.ForeColor = Color.Green;
                   
                }));   
            };

            ch.DataFailCallBack = (i) => {
                this.Invoke(new EventHandler(delegate {
                   

                    lblName.Text ="";
                    lblSex.Text = "";
                    lblNation.Text = "";
                    lblAddress.Text ="";
                    lblCardNo.Text = "";
                    lblBrith.Text ="";
                    pictureBox1.Image = null;
                    pictureBox2.Image = null;

                    lblTime.Text = DateTime.Now.ToString();

                 
                    lblResult.Text = "认证失败";
                    lblResult.ForeColor = Color.Red;
                  
                }));
            };
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //必须
            ch.CleanInfo();
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }

        private void groupBox1_Click(object sender, EventArgs e)
        {

        }
    }
}
